package utils;

import beans.AlgorithmDetail;
import beans.UILine;
import dao.AlgorithmDao;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class ParseUtil {
    private static HashMap<String, JSONObject> blocksJsonMap = null;
    private static AlgorithmDao algorithmDao = new AlgorithmDao();
    private static String PARALLEL_STRATEGY = "-ut";
    //BLOCK_LENGTH:描述左右相邻两个block之间应该隔多少个像素
    private static int BLOCK_LENGTH = 130;
    //BLOCK_HEIGHT:描述上下相邻两个block之间应该隔多少个像素
    private static int BLOCK_HEIGHT = 100;
    //START:描述开始节点的位置
    private static int START_X= 30;
    private static int START_Y= 140;
    //END:描述开始节点的位置
    private static int END_X= 810;
    private static int END_Y= 140;
    private static int BLOCK_NUM = (END_X-START_X)/BLOCK_LENGTH;
    /**
     * 由模型json解析出模型的输入
     * @param json
     * @return
     */
    private static JSONArray parseInputs(JSONObject json) {
        parseAlgorithmBlocks(json);
        JSONArray results = new JSONArray();
        JSONArray lines = json.getJSONArray("lines");
        Collection<?> uiLines = JSONArray.toCollection(lines, UILine.class);
        for (Object o : uiLines) {
            UILine uiLine = (UILine) o;
            if (uiLine.getPageSourceId().contains("Start")) {
                JSONObject result = new JSONObject();
                result.put("blockId",uiLine.getPageTargetId());
                result.put("algorithmId",blocksJsonMap.get(uiLine.getPageTargetId()).getString("dataId"));
                AlgorithmDetail algorithmDetail = algorithmDao.getAlgorithmDetailWithoutUserId(result.getString("algorithmId"));
                result.put("inputs", algorithmDetail.getAlgorithmInputs());
                results.add(result);
            }
        }
        return results;
    }

    /**
     * 由模型的json解析出模型的输出
     * @param json
     * @return
     */
    private static JSONArray parseOutputs(JSONObject json) {
        parseAlgorithmBlocks(json);
        JSONArray results = new JSONArray();
        JSONArray lines = json.getJSONArray("lines");
        Collection<?> uiLines = JSONArray.toCollection(lines, UILine.class);
        for (Object o : uiLines) {
            UILine uiLine = (UILine) o;
            if (uiLine.getPageTargetId().contains("End")) {
                JSONObject result = new JSONObject();
                result.put("blockId",uiLine.getPageSourceId());
                result.put("algorithmId",blocksJsonMap.get(uiLine.getPageSourceId()).getString("dataId"));
                result.put("outputs", algorithmDao.getAlgorithmDetailWithoutUserId(
                        result.getString("algorithmId")).getAlgorithmOutputs());
                results.add(result);
            }
        }
        return results;
    }

    /**
     * 由模型的json解析出模型的参数
     * @param json
     * @return
     */
    private static JSONArray parseParams(JSONObject json) {
        parseAlgorithmBlocks(json);
        JSONArray results = new JSONArray();
        JSONArray blocksArray = json.getJSONArray("blocks");
        for (int i = 0; i < blocksArray.size(); i++) {
            JSONObject blockObject = JSONObject.fromObject(blocksArray.get(i));
            if(blockObject.containsKey("paramsConfigDefault")){
                JSONObject result = new JSONObject();
                result.put("blockId",blockObject.getString("blockId"));
                result.put("algorithmId",blocksJsonMap.get(blockObject.getString("blockId")).getString("dataId"));
                result.put("paramsConfigDefault",blockObject.getJSONArray("paramsConfigDefault"));
                results.add(result);
            }
        }
        return results;
    }

    /**
     * 由模型的json解析模型中所有算法块的json，存放到以算法块的blockId为键名的map中
     * @param json
     */
    private static void  parseAlgorithmBlocks(JSONObject json) {
        if(blocksJsonMap==null){
            blocksJsonMap = new HashMap<>();
            JSONArray blocksArray = json.getJSONArray("blocks");
            for (int i = 0; i < blocksArray.size(); i++) {
                JSONObject blockObject = JSONObject.fromObject(blocksArray.get(i));
                blocksJsonMap.put(blockObject.getString("blockId"), blockObject);
            }
        }
    }

    /**
     * 解析模型的json，返回包含有模型输入、输出、参数的json object
     * @param json
     * @return
     * by:朱耀堃
     */
    public static JSONObject parseModelDetail(JSONObject json){
        json.put("input",parseInputs(json));
        json.put("output",parseOutputs(json));
        json.put("params",parseParams(json));
        json.put("data", parseDatas(json));
        blocksJsonMap = null;
        return  json;
    }

    /**
     * 由模型的json解析出模型的外部数据源信息
     * @param json
     * @return
     */
    private static JSONArray parseDatas(JSONObject json) {
        parseAlgorithmBlocks(json);
        JSONArray results = new JSONArray();
        JSONArray blocksArray = json.getJSONArray("blocks");
        for (int i = 0; i < blocksArray.size(); i++) {
            JSONObject blockObject = JSONObject.fromObject(blocksArray.get(i));
            if(blockObject.containsKey("inputConfig")){
                JSONArray inputs = blockObject.getJSONArray("inputConfig");
                for(int j=0;j<inputs.size();j++){
                    if(inputs.getJSONObject(j).containsKey("frontOutput")&&
                            inputs.getJSONObject(j).getJSONObject("frontOutput").getString("blockId").contains("uiData")){
                        JSONObject oneInput = inputs.getJSONObject(j);
                        JSONObject oneResult = new JSONObject();
                        oneResult.put("inputName", oneInput.getString("inputName"));
                        oneResult.put("blockId", blockObject.getString("blockId"));
                        oneResult.put("dataId", blockObject.getString("dataId"));
                        oneResult.put("dataName", inputs.getJSONObject(j).getJSONObject("frontOutput").getString("frontOutputName"));
                        results.add(oneResult);
                    }
                }
            }
        }
        return results;
    }

    /**
     * 将不完整的modelJson封装成为完整的modelJson
     * @param jsonObject ： 见resources/AnnotationCommit/CreateModelAndStartTask.json
     * @return
     */
    public static JSONObject generateModelJson(JSONObject jsonObject){
        JSONObject modelJson = new JSONObject();
        JSONArray lineArray = jsonObject.getJSONArray("lines");
        JSONArray blockArray = jsonObject.getJSONArray("blocks");
        int taskNumber = Integer.valueOf(jsonObject.getString("taskNumber"));
        int dataNum = 0;
        for(int i=0;i<blockArray.size();i++){
            JSONObject oneBlock = blockArray.getJSONObject(i);
            boolean isAlgorithm = oneBlock.getString("blockId").contains("uiAlgorithm");
            if(isAlgorithm){
                JSONArray paramsConfigDefault = oneBlock.getJSONArray("paramsConfigDefault");
                JSONArray paramConfig = new JSONArray();
                for(int j=0;j<taskNumber;j++){
                    paramConfig.add(paramsConfigDefault);
                }
                oneBlock.put("paramsConfig",paramConfig);
                oneBlock.put("isAlgorithm",isAlgorithm?"1":"0");
                oneBlock.put("blockClass",isAlgorithm?"uiAlgorithm":"uiModel");
                oneBlock.put("blockName","");
                oneBlock.put("blockTitle","");
                int block_x = (i%BLOCK_NUM)+1;
                int block_y = (i/BLOCK_NUM);
                oneBlock.put("blockX",START_X+block_x*BLOCK_LENGTH);
                oneBlock.put("blockY",START_Y+block_y*BLOCK_HEIGHT);
                oneBlock.put("paramNum",paramsConfigDefault.size());
            }
            if(oneBlock.getString("blockId").contains("uiData")){
                //这里可能data block超过六个之后，画布就画不出来了，因为START_Y=140，而BLOCK_HEIGHT=100，放不下两排
                oneBlock.put("blockClass","uiData");
                int block_x = (dataNum%BLOCK_NUM)+1;
                int block_y = (dataNum/BLOCK_NUM);
                oneBlock.put("blockX",START_X+block_x*BLOCK_LENGTH);
                oneBlock.put("blockY",START_Y-block_y*BLOCK_HEIGHT);
                dataNum++;
            }
        }
        //封装开始和结束节点的block
        JSONObject startBlock = new JSONObject();
        startBlock.put("blockId","uiStart_1");
        startBlock.put("blockClass","uiStart");
        startBlock.put("blockName","开始");
        startBlock.put("blockX",START_X);
        startBlock.put("blockY",START_Y);
        JSONObject endBlock = new JSONObject();
        endBlock.put("blockId","uiEnd_1");
        endBlock.put("blockClass","uiEnd");
        endBlock.put("blockName","结束");
        endBlock.put("blockX",END_X);
        endBlock.put("blockY",END_Y);
        blockArray.add(startBlock);
        blockArray.add(endBlock);

        modelJson.put("lines",lineArray);
        modelJson.put("blocks",blockArray);
        modelJson.put("taskNumber",taskNumber);
        modelJson.put("inputs",jsonObject.getJSONObject("params").getJSONArray("inputs"));
        modelJson.put("outputs",jsonObject.getJSONObject("params").getJSONArray("outputs"));
        modelJson.put("data",jsonObject.getJSONObject("params").getJSONArray("data"));
        modelJson.put("other",jsonObject.getJSONObject("params").getJSONArray("other"));
        return modelJson;
    }
    /**
     * 由模型的json和包含有输入、输出、参数等必要信息的json生成标准的task的启动json
     * 样例modelJson位于AnnotationFiles/模型json详情.json
     * 样例paramsJson位于AnnotationFiles/接口调用者保存任务接口参数说明.json
     * @param modelJson
     * @param paramsJson
     * @return
     */
    public static JSONObject parseTaskJson(JSONObject modelJson, JSONObject paramsJson){
        HashMap<String, JSONArray> paramMap = parseParamValues(paramsJson);
        int a = paramMap.size();
        //需要在modelJson中每一个block内将paramsConfig写入
        JSONArray blocksJson = modelJson.getJSONArray("blocks");
        for(int i=0;i<blocksJson.size();i++){
            JSONObject oneBlock = blocksJson.getJSONObject(i);
            String  blockId = oneBlock.getString("blockId");
            if(blockId.contains("Data")||blockId.contains("Start")||blockId.contains("End")){
                continue;
            }else{
                JSONArray temp = paramMap.get(blockId);
                oneBlock.put("paramsConfig", temp);
            }
            blocksJson.set(i,oneBlock);
        }
        JSONArray inputArray = paramsJson.getJSONArray("inputs");
        for(int i=0;i<inputArray.size();i++){
            JSONArray tempArray = inputArray.getJSONArray(i);
            for(int j=0;j<tempArray.size();j++){
                JSONObject temp = tempArray.getJSONObject(j);
                if(!temp.containsKey("blockName")){
                    temp.put("blockName", "任务"+(i+1)+"，算法"+(j+1));
                }
            }
        }
        JSONArray outputArray = paramsJson.getJSONArray("outputs");
        for(int i=0;i<outputArray.size();i++){
            JSONArray tempArray = outputArray.getJSONArray(i);
            for(int j=0;j<tempArray.size();j++){
                JSONObject temp = tempArray.getJSONObject(j);
                if(!temp.containsKey("blockName")){
                    temp.put("blockName", "任务"+(i+1)+"，算法"+(j+1));
                }
            }
        }
        modelJson.put("inputs",inputArray);
        modelJson.put("outputs",outputArray);
        modelJson.put("taskNumber",paramsJson.getString("taskNumber"));
        modelJson.put("other",parseOtherValues(paramsJson));
        //这里暂时没有外部数据源，所以先把data数组置为空
        if(!paramsJson.containsKey("data")){
            modelJson.put("data",new JSONArray());
        }else{
            modelJson.put("data",paramsJson.getJSONArray("data"));
        }
        return modelJson;
    }

    /**
     * 解析paramsJson中键名为params的json array
     * @param paramsJson 是一个批量任务的param值数组，数组中存着每一个子任务的param值；
     *                   而每一个HashMap的键名是blockId，键值是param对应的json array
     * @return map:<键名:blockId, 键值：参照任务json详情.json中每一个block的paramsConfig>
     */
    private static JSONArray parseOtherValues(JSONObject paramsJson){
        JSONArray otherArray = paramsJson.getJSONArray("other");
        for(int i=0;i<otherArray.size();i++){
            JSONObject oneOther = otherArray.getJSONObject(i);
            oneOther.put("ParallelStrategy",PARALLEL_STRATEGY);
        }
        return otherArray;
    }

    /**
     * 解析paramsJson中键名为params的json array
     * @param paramsJson 是一个批量任务的param值数组，数组中存着每一个子任务的param值；
     *                   而每一个HashMap的键名是blockId，键值是param对应的json array
     * @return map:<键名:blockId, 键值：参照任务json详情.json中每一个block的paramsConfig>
     */
    private static HashMap<String, JSONArray> parseParamValues(JSONObject paramsJson){
        HashMap<String, JSONArray> results = new HashMap<>();
        JSONArray batchParams = paramsJson.getJSONArray("params");
        for(int i=0;i<batchParams.size();i++){
            //i:每一个批量任务
            JSONArray oneParams = batchParams.getJSONArray(i);
            for(int j=0;j<oneParams.size();j++){
                //j:子任务中每一个算法块
                JSONObject param = oneParams.getJSONObject(j);
                if(results.containsKey(param.getString("blockId"))){
                    results.get(param.getString("blockId")).add(param.getJSONArray("param"));
                }else{
                    JSONArray one = new JSONArray();
                    one.add(param.getJSONArray("param"));
                    results.put(param.getString("blockId"),one);
                }
            }
        }
        return results;
    }

    public static void main(String[] args) {
        String paramsJson = "{\n" +
                "    \"fatherTaskId\":\"11\",\n" +
                "    \"modelId\": \"178\",\n" +
                "    \"params说明1\":\"这里params根据模型json返回值中每一个block下面的paramsConfigDefault值来配置，不过需要添加对应的blockId\",\n" +
                "    \"params说明2\":\"第1层：params是一个JSONArray，里面是每一个子任务对应的params的JSONArray；\",\n" +
                "    \"params说明3\":\"第2层（子任务的JSONArray）：里面是每一个算法参数配置对应的JSONObject\",\n" +
                "    \"params说明4\":\"第3层（每个算法块的JSONObject）：（blockId：算法块的id）；（param：算法的多个参数块的JSONArray）\",\n" +
                "    \"params说明5\":\"第4层（算法参数块的JSONObject）：(paramName：参数名称)；（paramValue：配置的参数值）\",\n" +
                "    \"params\": [\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"param\": [\n" +
                "                    {\n" +
                "                        \"paramName\": \"a\",\n" +
                "                        \"paramValue\": \"11\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"paramName\": \"b\",\n" +
                "                        \"paramValue\": \"12\"\n" +
                "                    }\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_2\",\n" +
                "                \"param\": [\n" +
                "                    {\n" +
                "                        \"paramName\": \"a\",\n" +
                "                        \"paramValue\": \"11\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"paramName\": \"b\",\n" +
                "                        \"paramValue\": \"12\"\n" +
                "                    }\n" +
                "                ]\n" +
                "            }\n" +
                "        ],\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"param\": [\n" +
                "                    {\n" +
                "                        \"paramName\": \"a\",\n" +
                "                        \"paramValue\": \"11\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"paramName\": \"b\",\n" +
                "                        \"paramValue\": \"12\"\n" +
                "                    }\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_2\",\n" +
                "                \"param\": [\n" +
                "                    {\n" +
                "                        \"paramName\": \"a\",\n" +
                "                        \"paramValue\": \"11\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"paramName\": \"b\",\n" +
                "                        \"paramValue\": \"12\"\n" +
                "                    }\n" +
                "                ]\n" +
                "            }\n" +
                "        ]\n" +
                "    ],\n" +
                "    \"inputs说明1\":\"这里inputs最里面一层的blockId的值是固定的：uiStart_1；frontOUtputName：是具体的输入的值，dataId可以为空\",\n" +
                "    \"inputs说明2\":\"第1层：inputs是一个JSONArray，里面是每一个子任务对应的inputs的JSONArray；\",\n" +
                "    \"inputs说明3\":\"第2层（子任务的JSONArray）：里面是作为输入算法的多个输入配置对应的JSONObject（是多个算法的多个输入）\",\n" +
                "    \"inputs说明4\":\"第3层（每个算法块的JSONObject）：（blockId：算法块的id））\",\n" +
                "    \"inputs说明5\":\"第4层（算法输入块的JSONObject）：(blockId：固定值uiStart_1)；（frontOUtputName：是具体的输入的值）\",\n" +
                "    \"inputs\": [\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"blockName\": \"01:智慧城市3\",\n" +
                "                \"inputName\": \"-i1\",\n" +
                "                \"frontOutput\": {\n" +
                "                    \"frontOutputName说明\":\"该字段的值即为算法块uiAlgorithm_1输入名称为-i1的输入的具体的值\",\n" +
                "                    \"frontOutputName\": \"a/a_b/a_b_b.jpg\",\n" +
                "                    \"blockId说明\":\"该字段的值内容固定\",\n" +
                "                    \"blockId\": \"uiStart_1\",\n" +
                "                    \"dataId\": \"\"\n" +
                "                }\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"blockName\": \"01:智慧城市3\",\n" +
                "                \"inputName\": \"-i2\",\n" +
                "                \"frontOutput\": {\n" +
                "                    \"frontOutputName\": \"a/a_b/a_b_b.jpg\",\n" +
                "                    \"blockId\": \"uiStart_1\",\n" +
                "                    \"dataId\": \"\"\n" +
                "                }\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_2\",\n" +
                "                \"blockName\": \"02:3-16-1\",\n" +
                "                \"inputName\": \"-i0\",\n" +
                "                \"frontOutput\": {\n" +
                "                    \"frontOutputName\": \"a/a_b/a_b_b.jpg\",\n" +
                "                    \"blockId\": \"uiStart_1\",\n" +
                "                    \"dataId\": \"\"\n" +
                "                }\n" +
                "            }\n" +
                "        ],\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"blockName\": \"01:智慧城市3\",\n" +
                "                \"inputName\": \"-i1\",\n" +
                "                \"frontOutput\": {\n" +
                "                    \"frontOutputName\": \"a/a_b/a_b_b.jpg\",\n" +
                "                    \"blockId\": \"uiStart_1\",\n" +
                "                    \"dataId\": \"\"\n" +
                "                }\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"blockName\": \"01:智慧城市3\",\n" +
                "                \"inputName\": \"-i2\",\n" +
                "                \"frontOutput\": {\n" +
                "                    \"frontOutputName\": \"a/a_b/a_b_b.jpg\",\n" +
                "                    \"blockId\": \"uiStart_1\",\n" +
                "                    \"dataId\": \"\"\n" +
                "                }\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_2\",\n" +
                "                \"blockName\": \"02:3-16-1\",\n" +
                "                \"inputName\": \"-i0\",\n" +
                "                \"frontOutput\": {\n" +
                "                    \"frontOutputName\": \"a/a_b/a_b_b.jpg\",\n" +
                "                    \"blockId\": \"uiStart_1\",\n" +
                "                    \"dataId\": \"\"\n" +
                "                }\n" +
                "            }\n" +
                "        ]\n" +
                "    ],\n" +
                "    \"outputs说明1\":\"同输入的说明，第二层里面是多个算法的多个输出，outputAddress可以不填，值全部放到outputValue里面，blockName的值无所谓\",\n" +
                "    \"outputs\": [\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_5\",\n" +
                "                \"blockName\": \"05:generic1\",\n" +
                "                \"outputName\": \"-o0\",\n" +
                "                \"outputAddress\": \"b/\",\n" +
                "                \"outputValue\": \"11.2\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_4\",\n" +
                "                \"blockName\": \"04:3-14-2\",\n" +
                "                \"outputName\": \"-o0\",\n" +
                "                \"outputAddress\": \"b/\",\n" +
                "                \"outputValue\": \"12.1\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_4\",\n" +
                "                \"blockName\": \"04:3-14-2\",\n" +
                "                \"outputName\": \"-o2\",\n" +
                "                \"outputAddress\": \"\",\n" +
                "                \"outputValue\": \"13.3\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_4\",\n" +
                "                \"blockName\": \"04:3-14-2\",\n" +
                "                \"outputName\": \"-o1\",\n" +
                "                \"outputAddress\": \"\",\n" +
                "                \"outputValue\": \"14.2\"\n" +
                "            }\n" +
                "        ],\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_5\",\n" +
                "                \"blockName\": \"05:generic1\",\n" +
                "                \"outputName\": \"-o0\",\n" +
                "                \"outputAddress\": \"\",\n" +
                "                \"outputValue\": \"24.2\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_4\",\n" +
                "                \"blockName\": \"04:3-14-2\",\n" +
                "                \"outputName\": \"-o0\",\n" +
                "                \"outputAddress\": \"\",\n" +
                "                \"outputValue\": \"21.1\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_4\",\n" +
                "                \"blockName\": \"04:3-14-2\",\n" +
                "                \"outputName\": \"-o2\",\n" +
                "                \"outputAddress\": \"\",\n" +
                "                \"outputValue\": \"22.3\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_4\",\n" +
                "                \"blockName\": \"04:3-14-2\",\n" +
                "                \"outputName\": \"-o1\",\n" +
                "                \"outputAddress\": \"\",\n" +
                "                \"outputValue\": \"23.2\"\n" +
                "            }\n" +
                "        ]\n" +
                "    ],\n" +
                "    \"taskNumber\":\"2\",\n"+
                "    \"other说明\":\"优先级和并行策略\",\n" +
                "    \"other\": [\n" +
                "        {\n" +
                "            \"Priority\": \"50\",\n" +
                "            \"ParallelStrategy\": \"-ut\"\n" +
                "        }\n" +
                "    ]\n" +
                "}";
        String modelJson = "{\n" +
                "    \"blocks\": [\n" +
                "        {\n" +
                "            \"blockId\": \"uiStart_1\",\n" +
                "            \"blockClass\": \"uiStart\",\n" +
                "            \"blockName\": \"开始\",\n" +
                "            \"blockX\": 108,\n" +
                "            \"blockY\": 119\n" +
                "        },\n" +
                "        {\n" +
                "            \"dataId\": \"378\",\n" +
                "            \"isAlgorithm\": \"1\",\n" +
                "            \"blockId\": \"uiAlgorithm_1\",\n" +
                "            \"blockClass\": \"uiAlgorithm\",\n" +
                "            \"blockName\": \"01:智慧城市3\",\n" +
                "            \"blockTitle\": \"智慧城市3\",\n" +
                "            \"blockX\": 241,\n" +
                "            \"blockY\": 62,\n" +
                "            \"paramNum\": \"2\",\n" +
                "            \"paramsConfigDefault\": [\n" +
                "                {\n" +
                "                    \"paramName\": \"a\",\n" +
                "                    \"paramValue\": \"11\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"paramName\": \"b\",\n" +
                "                    \"paramValue\": \"22\"\n" +
                "                }\n" +
                "            ],\n" +
                "            \"cpuNum\": 0\n" +
                "        },\n" +
                "        {\n" +
                "            \"dataId\": \"372\",\n" +
                "            \"isAlgorithm\": \"1\",\n" +
                "            \"blockId\": \"uiAlgorithm_2\",\n" +
                "            \"blockClass\": \"uiAlgorithm\",\n" +
                "            \"blockName\": \"02:3-16-1\",\n" +
                "            \"blockTitle\": \"3-16-1\",\n" +
                "            \"blockX\": 262,\n" +
                "            \"blockY\": 213,\n" +
                "            \"paramNum\": \"1\",\n" +
                "            \"paramsConfigDefault\": [\n" +
                "                {\n" +
                "                    \"paramName\": \"-p0\",\n" +
                "                    \"paramValue\": \"11\"\n" +
                "                }\n" +
                "            ],\n" +
                "            \"cpuNum\": 0\n" +
                "        },\n" +
                "        {\n" +
                "            \"dataId\": \"373\",\n" +
                "            \"isAlgorithm\": \"1\",\n" +
                "            \"blockId\": \"uiAlgorithm_3\",\n" +
                "            \"blockClass\": \"uiAlgorithm\",\n" +
                "            \"blockName\": \"03:32-test\",\n" +
                "            \"blockTitle\": \"32-test\",\n" +
                "            \"blockX\": 435,\n" +
                "            \"blockY\": 130,\n" +
                "            \"paramNum\": \"1\",\n" +
                "            \"inputConfig\": [\n" +
                "                {\n" +
                "                    \"inputName\": \"-i0\",\n" +
                "                    \"frontOutput\": {\n" +
                "                        \"frontOutputName\": \"+uiData_1+1\",\n" +
                "                        \"blockId\": \"uiData_1\",\n" +
                "                        \"dataId\": \"\"\n" +
                "                    }\n" +
                "                }\n" +
                "            ],\n" +
                "            \"paramsConfigDefault\": [\n" +
                "                {\n" +
                "                    \"paramName\": \"-p0\",\n" +
                "                    \"paramValue\": \"11\"\n" +
                "                }\n" +
                "            ],\n" +
                "            \"cpuNum\": 0\n" +
                "        },\n" +
                "        {\n" +
                "            \"dataId\": \"369\",\n" +
                "            \"isAlgorithm\": \"1\",\n" +
                "            \"blockId\": \"uiAlgorithm_4\",\n" +
                "            \"blockClass\": \"uiAlgorithm\",\n" +
                "            \"blockName\": \"04:3-14-2\",\n" +
                "            \"blockTitle\": \"3-14-2\",\n" +
                "            \"blockX\": 632,\n" +
                "            \"blockY\": 63,\n" +
                "            \"paramNum\": \"3\",\n" +
                "            \"inputConfig\": [\n" +
                "                {\n" +
                "                    \"inputName\": \"-i0\",\n" +
                "                    \"frontOutput\": {\n" +
                "                        \"frontOutputName\": \"-o0\",\n" +
                "                        \"blockId\": \"uiAlgorithm_3\",\n" +
                "                        \"dataId\": \"373\"\n" +
                "                    }\n" +
                "                },\n" +
                "                {\n" +
                "                    \"inputName\": \"-i2\",\n" +
                "                    \"frontOutput\": {\n" +
                "                        \"frontOutputName\": \"-o0\",\n" +
                "                        \"blockId\": \"uiAlgorithm_3\",\n" +
                "                        \"dataId\": \"373\"\n" +
                "                    }\n" +
                "                },\n" +
                "                {\n" +
                "                    \"inputName\": \"-i1\",\n" +
                "                    \"frontOutput\": {\n" +
                "                        \"frontOutputName\": \"-o0\",\n" +
                "                        \"blockId\": \"uiAlgorithm_3\",\n" +
                "                        \"dataId\": \"373\"\n" +
                "                    }\n" +
                "                }\n" +
                "            ],\n" +
                "            \"paramsConfigDefault\": [\n" +
                "                {\n" +
                "                    \"paramName\": \"-p0\",\n" +
                "                    \"paramValue\": \"11\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"paramName\": \"-p2\",\n" +
                "                    \"paramValue\": \"22\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"paramName\": \"-p1\",\n" +
                "                    \"paramValue\": \"33\"\n" +
                "                }\n" +
                "            ],\n" +
                "            \"cpuNum\": 0\n" +
                "        },\n" +
                "        {\n" +
                "            \"dataId\": \"366\",\n" +
                "            \"isAlgorithm\": \"1\",\n" +
                "            \"blockId\": \"uiAlgorithm_5\",\n" +
                "            \"blockClass\": \"uiAlgorithm\",\n" +
                "            \"blockName\": \"05:generic1\",\n" +
                "            \"blockTitle\": \"generic1\",\n" +
                "            \"blockX\": 643,\n" +
                "            \"blockY\": 274,\n" +
                "            \"paramNum\": \"2\",\n" +
                "            \"inputConfig\": [\n" +
                "                {\n" +
                "                    \"inputName\": \"-i0\",\n" +
                "                    \"frontOutput\": {\n" +
                "                        \"frontOutputName\": \"+uiData_2+1\",\n" +
                "                        \"blockId\": \"uiData_2\",\n" +
                "                        \"dataId\": \"\"\n" +
                "                    }\n" +
                "                }\n" +
                "            ],\n" +
                "            \"paramsConfigDefault\": [\n" +
                "                {\n" +
                "                    \"paramName\": \"-p0\",\n" +
                "                    \"paramValue\": \"11\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"paramName\": \"-p3\",\n" +
                "                    \"paramValue\": \"22\"\n" +
                "                }\n" +
                "            ],\n" +
                "            \"cpuNum\": 0\n" +
                "        },\n" +
                "        {\n" +
                "            \"blockId\": \"uiData_1\",\n" +
                "            \"blockClass\": \"uiData\",\n" +
                "            \"blockName\": \"外部数据源1\",\n" +
                "            \"blockX\": 365,\n" +
                "            \"blockY\": 319\n" +
                "        },\n" +
                "        {\n" +
                "            \"blockId\": \"uiData_2\",\n" +
                "            \"blockClass\": \"uiData\",\n" +
                "            \"blockName\": \"外部数据源2\",\n" +
                "            \"blockX\": 535,\n" +
                "            \"blockY\": 340\n" +
                "        },\n" +
                "        {\n" +
                "            \"blockId\": \"uiEnd_1\",\n" +
                "            \"blockClass\": \"uiEnd\",\n" +
                "            \"blockName\": \"结束\",\n" +
                "            \"blockX\": 754,\n" +
                "            \"blockY\": 162\n" +
                "        }\n" +
                "    ],\n" +
                "    \"lines\": [\n" +
                "        {\n" +
                "            \"pageSourceId\": \"uiStart_1\",\n" +
                "            \"pageTargetId\": \"uiAlgorithm_1\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"pageSourceId\": \"uiStart_1\",\n" +
                "            \"pageTargetId\": \"uiAlgorithm_2\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"pageSourceId\": \"uiAlgorithm_1\",\n" +
                "            \"pageTargetId\": \"uiAlgorithm_3\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"pageSourceId\": \"uiAlgorithm_2\",\n" +
                "            \"pageTargetId\": \"uiAlgorithm_3\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"pageSourceId\": \"uiAlgorithm_3\",\n" +
                "            \"pageTargetId\": \"uiAlgorithm_4\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"pageSourceId\": \"uiAlgorithm_3\",\n" +
                "            \"pageTargetId\": \"uiAlgorithm_5\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"pageSourceId\": \"uiAlgorithm_5\",\n" +
                "            \"pageTargetId\": \"uiEnd_1\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"pageSourceId\": \"uiAlgorithm_4\",\n" +
                "            \"pageTargetId\": \"uiEnd_1\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"pageSourceId\": \"uiData_1\",\n" +
                "            \"pageTargetId\": \"uiAlgorithm_3\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"pageSourceId\": \"uiData_2\",\n" +
                "            \"pageTargetId\": \"uiAlgorithm_5\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"taskNumber\": \"1\"\n" +
                "}";
        JSONObject param = JSONObject.fromObject(paramsJson);
        JSONObject model = JSONObject.fromObject(modelJson);
        JSONObject result = parseTaskJson(model,param);
        Log4jInit.logger.info(result.toString());
    }
}
